import { create } from "zustand";
import { persist } from "zustand/middleware";

// 定义状态类型
interface CounterState {
  count1: number;
  increment1: () => void;
  decrement1: () => void;
}

// 创建持久化的 Zustand store
const localStore = create<CounterState>()(
  persist(
    (set) => ({
      count1: 0,
      increment1: () => set((state) => ({ count1: state.count1 + 1 })),
      decrement1: () => set((state) => ({ count1: state.count1 - 1 })),
    }),
    {
      name: "counter-storage", // 存储的 key 名称
      // storage: localStorage, // 使用 localStorage 进行存储
    }
  )
);

export default localStore;
